﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Model.MetadataTypes;
namespace Model.Entities
{
    /// <summary>
    /// 实体类 无线电监测设施基本表, 此类请勿动，以方便表字段更改时重新生成覆盖
    /// </summary>
    [Serializable]
    [MetadataType(typeof(RMBT_FACILITY_Metadata))]
    public partial class RMBT_FACILITY
    {
        /// <summary>
        /// 创建<see cref="RMBT_FACILITY"/>的实例
        /// </summary>
        public RMBT_FACILITY()
        {
                _rmbt_facility_equipmentCollection = new List<RMBT_FACILITY_EQUIPMENT>();
		                }
        /// <summary>
        /// 监测设施标识【主键】
        /// </summary>
        public virtual string MFID { get; set; }

        		
        /// <summary>
        /// 行政区代码【RMBT_CODE_AREACODE(CODE_ID)】
        /// </summary>
        public virtual string AREACODE { get; set; }

    		
        /// <summary>
        /// 监测设施分类【RMBT_CODE_FACILITYTYPE(CODE_ID)】
        /// </summary>
        public virtual string MFTYPE { get; set; }

    		
        /// <summary>
        /// 投入使用日期
        /// </summary>
        public virtual DateTime RUNNINGDATE { get; set; }

    		
        /// <summary>
        /// 废除日期
        /// </summary>
        public virtual DateTime? REPEALDATE { get; set; }

            private IList<RMBT_FACILITY_EQUIPMENT> _rmbt_facility_equipmentCollection;
        /// <summary>
        /// 所拥有的【无线电监测设备信息表】的集合
        /// </summary>
        public virtual ReadOnlyCollection<RMBT_FACILITY_EQUIPMENT> RMBT_FACILITY_EQUIPMENTCollection { get; }

        /// <summary>
        /// 添加一个【无线电监测设备信息表】
        /// </summary>
        /// <param name="rmbt_facility_equipment">要添加的【无线电监测设备信息表】</param>
        /// <exception cref="ArgumentNullException"><paramref name="rmbt_facility_equipment"/>值为null。</exception>
        /// <exception cref="ArgumentException"><paramref name="rmbt_facility_equipment"/>已经被添加到某个<see cref="RMBT_FACILITY"/>当中。</exception>
        public virtual void AddRMBT_FACILITY_EQUIPMENT(RMBT_FACILITY_EQUIPMENT rmbt_facility_equipment)
        {
            if (rmbt_facility_equipment == null)
            {
                throw new ArgumentNullException("rmbt_facility_equipment");
            }
            if(rmbt_facility_equipment.RMBT_FACILITY != null)
            {
                throw new ArgumentException("rmbt_facility_equipment已被添加到某个RMBT_FACILITY当中，必须先从其中移除掉后才能添加到本实例中。", "rmbt_facility_equipment");
            }
            rmbt_facility_equipment.RMBT_FACILITY = this;
            _rmbt_facility_equipmentCollection.Add(rmbt_facility_equipment);
        }

        /// <summary>
        /// 移除一个【无线电监测设备信息表】
        /// </summary>
        /// <param name="rmbt_facility_equipment">要移除的【无线电监测设备信息表】</param>
        /// <returns>如果已成功移除<paramref name="rmbt_facility_equipment"/>，则为 true；否则为 false。 如果没有找到<paramref name="rmbt_facility_equipment"/>，该方法也会返回 false。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="rmbt_facility_equipment"/>值为null。</exception>
        public virtual bool RemoveRMBT_FACILITY_EQUIPMENT(RMBT_FACILITY_EQUIPMENT rmbt_facility_equipment)
        {
            if (rmbt_facility_equipment == null)
            {
                throw new ArgumentNullException("rmbt_facility_equipment");
            }
            bool result = _rmbt_facility_equipmentCollection.Remove(rmbt_facility_equipment);
            if(result)
            {
                rmbt_facility_equipment.RMBT_FACILITY = null;
            }
            return result;
        }

        /// <summary>
        /// 清空【无线电监测设备信息表】集合
        /// </summary>
        /// <returns>移除的【无线电监测设备信息表】条数</returns>
		public virtual int ClearRMBT_FACILITY_EQUIPMENTCollection()
        {
            int count = _rmbt_facility_equipmentCollection.Count;
            foreach (var rmbt_facility_equipment in _rmbt_facility_equipmentCollection)
            {
                rmbt_facility_equipment.RMBT_FACILITY = null;
            }
            _rmbt_facility_equipmentCollection.Clear();
            return count;
        }

		
        public override bool Equals(object obj)
        {
            RMBT_FACILITY model = obj as RMBT_FACILITY;
            return model != null && (ReferenceEquals(MFID,null) ? ReferenceEquals(model.MFID, null) : MFID.Equals(model.MFID));
        }
        public override int GetHashCode()
        {
            int hash = GetType().GetHashCode();
            hash = (hash * 397) ^ (ReferenceEquals(MFID, null) ? 0 : MFID.GetHashCode());
            return hash;
        }
    }
}
